package main

import (
	"flag"
	"log"
	"net/http"
	"time"

	"github.com/gin-gonic/gin"
	"myschools.me/dingtalk/config"
)

func main() {
	addr := flag.String("addr", ":8080", "service address")
	c := flag.String("c", "config.yaml", "file of config")
	flag.Parse()

	//配置初始化
	config.Init(c)

	r := gin.Default()
	r.Use(gin.Recovery())

	setupRouters(r)

	s := &http.Server{
		Addr:           *addr,
		Handler:        r,
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}
	log.Printf("api for dingtalk service on %s", *addr)
	if err := s.ListenAndServe(); err != nil {
		log.Fatalf("service stop! error: %s\r\n", err.Error())
	}
}
